<script setup>
import {reactive, ref} from "vue";
import {useRoleStore} from "@/stores/roleStore.js";
import {ElMessage} from "element-plus";

const roleStore = useRoleStore();
const dialogVisible = ref(false)
const createRole = reactive({
  name:'',
  code:'',
  dataScope: '',
  aclIds: [],
})
const rules = ref({
  name: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
  code: [{ required: true, message: '请输入角色编码', trigger: 'blur' }],
  dataScope: [{ required: true, message: '请选择数据权限范围', trigger: 'blur' }],
  aclIds: [{ required: true, message: '请输入角色权限列表', trigger: 'blur' }],
})
const createRoleFormRef = ref(null)

const submitForm = () => {
  createRoleFormRef.value?.validate().then(() => {
    console.log('校验通过2222')
    roleStore.createRole({
      ...createRole
    })
  }).catch(() => {
    ElMessage('请填写完整信息')
  })
}
const show = () => {
  dialogVisible.value = true
}
//对外暴露show
defineExpose({
  show
})
</script>

<template>
  <el-dialog
      title="创建角色"
      v-model="dialogVisible"
      width="50%"
  >
    <el-form :model="createRole" :rules="rules" ref="createRoleFormRef" label-width="110px">
      <el-form-item label="角色名称" prop="name">
        <el-input v-model="createRole.name" placeholder="请输入权限名称"></el-input>
      </el-form-item>
      <el-form-item label="角色编码" prop="code">
        <el-input v-model="createRole.code" placeholder="请输入权限码"></el-input>
      </el-form-item>
      <el-form-item label="数据权限范围" prop="dataScope">
        <el-select v-model="createRole.dataScope" placeholder="请选择权限类型">
          <el-option label="全部" value="1"></el-option>
          <el-option label="本部" value="2"></el-option>
          <el-option label="自定义" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="权限点ID" prop="aclIds">
        <el-input v-model="createRole.aclIds" placeholder="请输入权限点ID列表"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped>

</style>